PriorThe Distance Formula and Absolute ValueNext

Figure (Distance Formula) shows a simple derivation for a formula that lets us calculate the distance between two points. In the figure we see that the horizontal and vertical sides of the right triangle are labeled with their magnitude. For example, $d_{x},$ the horizontal side has magnitude $x_{1}-x_{0}$, as can be seen by observing the point values for the two points $(x_{0},y_{0})$ and $(x_{1},y_{0}).$ One just makes a right triangle from the two points of the line and uses the Pythagorean relation for the hypotenuse.

Distance Formula
$\mathbf{Distance Formula}$. The distance between two points, P & Q can be calculated by making a right triangle from the two points and noting that the side lengths are known. From the Pythagorean theorem, the hypotenuse length is also known and it is the distance between the two points. Unless symbolic algebra is needed, we use $\left|P-Q\right|$ to obtain values and let computers do the work.

In all of the popular computer algebra systems (Matlab, Mathematica, Maple, Maxima, SAGE, Geogebra), the absolute value function applied to a direction vector will return the magnitude of the vector. Why would that be? Consider that the magnitude of a real number can be described as the square root of itself squared. Equation 1 is One definition of absolute value with a scaler. $$\left|x\right|=\sqrt{x^{2}} \tag{1} \label{1}$$ It may be a little confusing, but the square root symbol, $\sqrt{\ }$, always refers to only the principle square root, i.e. a positive real number. If one has an equation, such as $x^{2}=a$, then $x=\pm\sqrt{a}$, again implying that the square root symbol yields only the principle square root.

In the complex plane, the magnitude of a number is the distance of the point from the origin when graphed as the complex part on one axis and the real part on the other axis. Thus the distance formula would give its distance from the origin which is called its magnitude or modulus. This magnitude is then extended to vector space in general and the absolute value function for a Euclidean vector is defined as the distance formula to give the magnitude. In vector space, the notation is often given as double vertical lines. In Eq $\eqref{2}$ we express the absolute value of a vector enclosed by double vertical lines using the definition from equation $\eqref{1}$. You may not find it obvious that the absolute value of a vector is equal to the square root of the sum of its squared elements! Equation $\eqref{2}$ follows from a $\mathbf{\text{second definition of absolute value.}}$ We define $\mathbf{\color{red}\text{absolute value}}$ as the distance of a point from the zero origin. In vector space, having as many dimensions as the vector has elements, the vector describes a point location. The distance of that point from the origin is given by $\eqref{2}$. The difference between $\eqref{1}$ and $\eqref{2}$ is not really a change in definition, but rather the extension of the definition from 1-dimension to many dimensions. Eq $\eqref{2}$ is called the $\mathbf{\color{red}\text{Euclidean norm}}.$ $$\left\Vert (x_{1},x_{2},\ ...\ ,x_{n})\right\Vert =\sqrt{\sum_{i=1}^{n}x_{i}^{2}}\tag{2} \label{2}$$ For exactly two dimensions the distance from the origin $(0,0)$ is \[ \Vert(x,y)\Vert=\sqrt{(x)^{2}+(y)^{2}} \] and the distance between two point, $(x_{0},y_{0})$ and $(x_{1},y_{1})$ is $$\Vert(x,y)\Vert=\sqrt{(x_{0}-x_{1})^{2}+(y_{0}-y_{1})^{2}}.\tag{3} \label{3}$$ On a Cartesian coordinate system in 2 dimensions, absolute value is also the distance of a point $(x,y)$ from the origin. If one obtains the absolute value of the difference between two points, the subtraction is performed first and then the distance from the origin for the result is presented as the absolute value. Said more simply, the distance between two points is the absolute value of the points when treated as vectors. Still another way to express the same is that the distance between two points is the magnitude of their direction vector.

Example 1 Let $P=\left(4,6\right)$ and $Q=(3,8)$. Find the distance between these two 2-d points using the relationship of equation Eq $\eqref{2}$.

In programming code, the absolute value function performs the distance formula calculation on any pair of tuples. Look at the abs(P) function here.

var('p q P');
p=7;
q=5;
P=vector(QQ,[p,q]);
abs(P);
Code for line segment length in Sage. We define two numbers and put them into a vector. $\text{direction vector: } P=(7,5)$ It originates at $(0,0).$ Taking the absolute value then yields the line length. The result is $\sqrt{74}$. If one applies the distance formula then it is obvious that the vector length is correct.
$x_1=0;$
$x_2=7;$
$y_1=0;$
$y_2=5;$
$\sqrt{(7-0)^{2}+(5-0)^{2}}$ = $\sqrt{(x_{2}-x_{1})^{2}+(y_{2}-y_{1})^{2}}$ $$\left|P\right|=\sqrt{(P_{x}-0)^{2}+(P_{y}-0)^{2}}$$ $$\left|P-Q\right|=\sqrt{(P_{x}-Q_{x})^{2}+(P_{y}-Q_{y})^{2}}$$

If we were using a computer algebra system, we would be done by typing in $\left\Vert P-Q\right\Vert $ or $abs(P-Q)$ and the machine will return the distance between the points. Of course by the definition, this works for all vector spaces (i.e. all dimensions).